<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="left-panel"> </div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="标题 / 项目名称" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="recordId" stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="费用标题" prop="title" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="项目名称" prop="pTitle" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="项目编号" prop="projectCode" width="100"></el-table-column>
				<el-table-column label="项目预算" prop="pTotalCost" width="100">
					<template #default="scope">
						{{scope.row.pTotalCost}}/万元
					</template>
				</el-table-column>
				<el-table-column label="费用支出" prop="cTotalCost" width="100">
					<template #default="scope">
						{{scope.row.cTotalCost}}/万元
					</template>
				</el-table-column>
				<el-table-column label="项目类型" prop="projectTypeName" width="100"></el-table-column>
				<el-table-column label="支出时间" prop="happenTime" width="100"></el-table-column>
				<el-table-column label="项目负责人" prop="chargeUserName" width="100"></el-table-column>
				<el-table-column label="预算科目" prop="budgetAccountName" width="100"></el-table-column>
				<el-table-column label="上报人" prop="createUserName" width="100"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="100">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<applyDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></applyDetails>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import applyDetails from '@/views/finance/budget/reporting/details'
export default {
	name: 'Budget Cost Search',
	components: {
		scSelectFilter,
		applyDetails
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave:false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "所属项目",
					key: "projectId",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}],
				}
			],
			apiObj: this.$API.finance.budget.getChildBudgetCostList,
			search: {
				date:'',
				projectId:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.getAllParentBudgetProject();
	},
	methods: {
		async getAllParentBudgetProject()
		{
			var res = await this.$API.finance.budget.getAllParentBudgetProject.get();
			if (res.code == 200) {
				this.filterData[1].options=this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.projectId = data.projectId;
			this.$refs.table.upData(this.search)
		},
		table_show(row) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row)
			})
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
